import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Patch,
  UseInterceptors,
  ClassSerializerInterceptor,
  UseGuards,
} from '@nestjs/common';
import { MajorService } from './major.service';
import { CreateMajorDto } from './dto/create-major.dto';
import { UpdateMajorDto } from './dto/update-major.dto';
import {
  ApiBody,
  ApiOperation,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { JwtGuard } from '../guards/jwt.guards';

@Controller('major')
@UseInterceptors(ClassSerializerInterceptor)
@UseGuards(JwtGuard) // 校验token是否通过
@ApiTags('专业模块')
export class MajorController {
  constructor(private readonly majorService: MajorService) {}

  @Post()
  @ApiOperation({ summary: '创建专业' })
  @ApiBody({ type: CreateMajorDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateMajorDto,
  })
  create(@Body() createMajorDto: CreateMajorDto) {
    return this.majorService.create(createMajorDto);
  }

  @Get()
  @ApiOperation({ summary: '查询所有专业' })
  findAll() {
    return this.majorService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '查询专业详情' })
  @ApiQuery({ name: 'id', required: true })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateMajorDto,
  })
  findOne(@Param('id') id: number) {
    return this.majorService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '专业更新' })
  @ApiQuery({ name: 'id', required: true, description: '专业id' })
  @ApiBody({ type: CreateMajorDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateMajorDto,
  })
  update(@Param('id') id: number, @Body() updateMajorDto: UpdateMajorDto) {
    return this.majorService.update(id, updateMajorDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '专业删除' })
  @ApiQuery({ name: 'id', required: true, description: '专业id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateMajorDto,
  })
  remove(@Param('id') id: number) {
    return this.majorService.remove(+id);
  }
}
